#ifndef MODELS_H
#define MODELS_H

#include <QString>
#include <QDateTime>
#include <QJsonObject>

// 用户基类
class User {
public:
    int id;
    QString username;
    QString password;
    QString realName;
    QString idCard;
    QString phone;
    int role;
    QDateTime createTime;
    
    QJsonObject toJson() const;
    static User fromJson(const QJsonObject& json);
};

// 患者信息
class Patient : public User {
public:
    QString gender;
    QDate birthDate;
    QString address;
    QString emergencyContact;
    QString emergencyPhone;
    QString allergies;
    QString medicalHistory;
    
    QJsonObject toJson() const;
    static Patient fromJson(const QJsonObject& json);
};

// 医生信息
class Doctor : public User {
public:
    int departmentId;
    QString departmentName;
    QString title;
    QString specialty;
    QString education;
    int experience;
    QString introduction;
    QString workTime;           // 上班时间
    double consultationFee;     // 挂号费用
    int dailyPatientLimit;      // 单日患者上限
    int bookedCount;            // 已预约人数（用于显示）
    int remainingSlots;         // 剩余预约数（用于显示）
    QString clinicType;         // 门诊类型：普通门诊、专家门诊、专病门诊、急诊
    
    QJsonObject toJson() const;
    static Doctor fromJson(const QJsonObject& json);
};

// 预约信息
class Appointment {
public:
    int id;
    int patientId;
    int doctorId;
    QDateTime appointmentTime;
    QString status;
    QString cancelReason;  // 取消原因
    QString symptoms;
    int medicalRecordId;   // 关联病历ID
    QDateTime createTime;
    
    QJsonObject toJson() const;
    static Appointment fromJson(const QJsonObject& json);
};

// 病历信息
class MedicalRecord {
public:
    int id;
    int patientId;
    int doctorId;
    int appointmentId;   // 关联的预约ID
    QString doctorName;  // 医生姓名（用于显示）
    QDateTime visitTime;
    QString chiefComplaint;
    QString presentIllness;
    QString physicalExam;
    QString diagnosis;
    QString treatment;
    QString notes;
    
    QJsonObject toJson() const;
    static MedicalRecord fromJson(const QJsonObject& json);
};

// 处方信息
class Prescription {
public:
    int id;
    int medicalRecordId;
    int patientId;
    int doctorId;
    int appointmentId;   // 关联的预约ID
    QDateTime prescriptionTime;
    QString medications;
    QString dosage;
    QString usage;
    QString frequency;
    int days;
    QString notes;
    
    QJsonObject toJson() const;
    static Prescription fromJson(const QJsonObject& json);
};

// 检查单信息
class ExamRequest {
public:
    int id;
    int medicalRecordId;
    int patientId;
    int doctorId;
    QString examType;
    QString examItem;
    QString purpose;
    QString status;
    QString result;
    QDateTime requestTime;
    QDateTime resultTime;
    
    QJsonObject toJson() const;
    static ExamRequest fromJson(const QJsonObject& json);
};

// 科室信息
class Department {
public:
    int id;
    QString name;
    QString description;
    QString location;
    QString phone;
    
    QJsonObject toJson() const;
    static Department fromJson(const QJsonObject& json);
};

// 缴费记录
class Payment {
public:
    int id;
    int patientId;
    QString paymentType;
    double amount;
    QString status;
    QString description;
    QDateTime paymentTime;
    
    QJsonObject toJson() const;
    static Payment fromJson(const QJsonObject& json);
};

// 医患沟通消息
class Message {
public:
    int id;
    int senderId;
    int receiverId;
    QString messageContent;
    QDateTime sendTime;
    bool isRead;
    
    // 扩展字段（用于显示）
    QString senderName;
    QString receiverName;
    
    QJsonObject toJson() const;
    static Message fromJson(const QJsonObject& json);
};

// 打卡记录
class AttendanceRecord {
public:
    int id;
    int doctorId;
    QDate attendanceDate;
    QTime attendanceTime;
    QDateTime createTime;
    
    QJsonObject toJson() const;
    static AttendanceRecord fromJson(const QJsonObject& json);
};

// 请假申请
class LeaveRequest {
public:
    int id;
    int doctorId;
    QString phone;
    QString leaveType;      // 因公/因私
    QDate startDate;
    QDate endDate;
    QString reason;
    QString status;         // 待审批/已批准/已拒绝/已销假
    QDateTime requestTime;
    QDateTime cancelTime;   // 销假时间
    
    QJsonObject toJson() const;
    static LeaveRequest fromJson(const QJsonObject& json);
};

// 药物信息
class Medicine {
public:
    int id;
    QString name;
    QString category;
    QString manufacturer;
    QString specification;
    double price;
    QString usageInstruction;
    QString precautions;
    bool isPopular;
    QDateTime createTime;
    
    QJsonObject toJson() const;
    static Medicine fromJson(const QJsonObject& json);
};

// 通知信息
class Notification {
public:
    int id;
    int userId;
    int userRole;           // 1=患者 2=医生
    QString type;           // appointment_cancelled, new_message, appointment_created, leave_approved等
    QString title;
    QString content;
    int relatedId;          // 关联的ID
    bool isRead;
    QDateTime createTime;
    
    QJsonObject toJson() const;
    static Notification fromJson(const QJsonObject& json);
};

#endif // MODELS_H

